<template>
  <div class="computed-demo">
    <h1>计算属性</h1>
    <p>今天是<input type="date" v-model="date"></p>
    <p>今天距离{{date}}还有{{daysFromNow}}天</p>
  </div>
</template>

<script>
export default {
  name: "ComputedDemo",
  data: function () {
    return {
      date: '2025-01-01'
    }
  },
  computed: {
    // 计算属性
    daysFromNow : function () {
      const today = new Date();
      const targetDate = new Date(this.date);
      const timeDiff = targetDate.getTime() - today.getTime();
      const daysDiff = timeDiff/ (24 * 60 * 60 * 1000);
      return Math.floor(daysDiff);
    }
  }
}
</script>

<style scoped>

</style>